package cn.edu.zjicm.wordsnet_d.adapter;

import java.util.List;

import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.util.NightModeUtil;
import cn.edu.zjicm.wordsnet_d.util.Utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;

public class AddSchoolAdapter extends BaseAdapter{

	Context mContext;
	List<String> nameList;
	boolean forSettingPlan;
	
	public AddSchoolAdapter(Context mContext,List<String> nameList,boolean forSettingPlan){
		this.mContext = mContext;
		this.nameList = nameList;
		this.forSettingPlan = forSettingPlan;
	}
	
	@Override
	public int getCount() {
		return nameList.size();
	}

	@Override
	public Object getItem(int position) {
		return nameList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		MyHolder holder = null;
		
		if(convertView==null){
			holder = new MyHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.view_add_school_item, parent,false);
			holder.layout = (RelativeLayout) convertView.findViewById(R.id.add_school_item_layout);
			holder.nameTv = (TextView) convertView.findViewById(R.id.add_school_item_name);
			holder.divider = (TextView) convertView.findViewById(R.id.add_school_divider);
			holder.selectImg = (ImageView) convertView.findViewById(R.id.iv);
			convertView.setTag(holder);
		}else{
			holder = (MyHolder) convertView.getTag();
		}
		
		if (NightModeUtil.isNightModeNow())
			holder.divider.setVisibility(View.GONE);
		else
			holder.divider.setVisibility(View.VISIBLE);
		
		if(position==0){
			Utils.setListItemTop(holder.layout);
		}else if(position==nameList.size()-1){
			Utils.setListItemBottom(holder.layout,holder.divider);
		}
		
		holder.nameTv.setText(nameList.get(position));
		
		if(forSettingPlan){
			holder.selectImg.setVisibility(View.VISIBLE);
		}
		
		return convertView;
	}

	class MyHolder{
		RelativeLayout layout;
		TextView nameTv;
		TextView divider;
		ImageView selectImg;
	}
	
}
